import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import 'application.dart';

class NavigatorUtils{

  //跳转
  static push(BuildContext context,String path,{bool replace = false, bool clearStack = false}){
    Application.router.navigateTo(context, path,replace: replace,clearStack: clearStack,transition: TransitionType.native);
  }

  //带返回值的跳转
  static pushResult(BuildContext context,String path,Function(Object) function,{bool replace=false,bool clearStack = false}){
    Application.router.navigateTo(context, path,replace: replace,clearStack: clearStack,transition: TransitionType.native).then((onValue){
      //页面返回的onValue为null
      if(onValue==null){
        return null;
      }
      function(onValue);
    }).catchError((onError){
      print('$onError');
    });
  }

  ///界面返回
  static void goBack(BuildContext context){
    Navigator.pop(context);
  }

  ///带参数返回
  static void goBackWithParams(BuildContext context,result){
    Navigator.pop(context,result);
  }
}